﻿(function(){
	//if (!window.external) return;

	var fnTrue = function(){ return true; };
	var $tag = function(tagName,obj){
		return (obj || document).getElementsByTagName(tagName);
	};
	// 遍历框架
	var TraverseFrames = function(win,fn){
		if (!win) return;
		fn(win);

		var o = win.frames;
		if (!o) return;
		for (var i=0,len=o.length; i<len; i++){
			TraverseFrames(o[i], fn);
		}
	};
	// 转换指定窗体内的模式窗口为非模式
	var ConvertModalDialog = function(win){
		if (win.eval){
			win.eval('window.showModalDialog = function(sURL, vArguments, sFeatures){win=window.open(sURL); win.dialogArguments=vArguments;}');
		}
	};
	
	// 移除文本框只读属性
	var RemoveRead = function(doc){
		var o = $tag('input',doc);
		for (var i=0,len=o.length; i<len; i++){
			o[i].removeAttribute('readOnly');
		}
	};
	// 激活失效项
	var EnableObject = function(doc){
		var o = $tag('*',doc);
		for (var i=0,len=o.length; i<len; i++){
			o[i].removeAttribute('disabled');
		}
	};
	// 解除鼠标限制
	var EnableMouse = function(doc){
		if (window.event){
			event.returnValue = true;
			event.cancelBubble = false;
		}

		doc.oncontextmenu = fnTrue;

		doc.onmousedown = fnTrue;
		doc.onmouseup = fnTrue;
		doc.onmouseout = fnTrue;
		doc.onmousemove = fnTrue;

		doc.onselect = fnTrue;
		doc.onselectstart = fnTrue;
		doc.ondragstart = fnTrue;
		doc.onbeforecopy = fnTrue;
		doc.oncopy = fnTrue;
		
		if (doc.body){
			EnableMouse(doc.body);
		}
	};

	TraverseFrames(window, function(win){
		ConvertModalDialog(win);

		var doc = win.document;
		EnableMouse(doc);
		EnableObject(doc);
		RemoveRead(doc);
	});
})();
